import json
import time
import pandas
import xlrd
from logs.Log import Log


# noinspection PyMethodMayBeStatic
class TimeSpan:
    def __init__(self):
        self.start_time = None
        self.end_time = None
        self.goodsJson = "../data/goods_config.json"
        self.goodsExcel = "../data/道具表-goods_config.xlsx"
        self.Log = Log()

    def XlrdExcel(self):
        xlrd.open_workbook(self.goodsExcel)
        print("XlrdTime")

    def JsonTime(self):
        with open(self.goodsJson, "r", encoding='utf-8') as f:
            json.load(f)
        print("JsonTime")

    def PandasTime(self):
        pandas.DataFrame(pandas.read_excel(self.goodsExcel, sheet_name=0))
        print("PandasTime")

    def ShowTime(self, method):
        start_time = time.time()
        method()
        end_time = time.time()
        print('耗时:', round(end_time - start_time, 2), 's')

    def Star(self):
        self.start_time = time.time()

    def End(self, name=None):
        self.end_time = time.time()
        if name is not None:
            my = f"【{name}】耗时:{round(self.end_time - self.start_time, 2)}s"
        else:
            my = f"耗时:{round(self.end_time - self.start_time, 2)}s"
        self.Log.Show(my, 30)
